package jax.lang;

/**
 * ...
 * @author tom
 */
class JBoolean {
	public var _native:Bool;
	public static var TRUE = new JBoolean(true);
	public static var FALSE = new JBoolean(false);
	public function new (v:Dynamic) {
		_native = if(Std.is(v, Bool))
			v;
		else if(Std.is(v, String))
			v.toLowerCase() == "true";
		else
			false;
	}
	public function hashCode():Int {
		return _native ? 1231 : 1237;
	}
	public function toString():String {
		return toString__(_native);
	}
	public function booleanValue():Bool {
		return _native;
	}
	public function equals(other:Dynamic):Bool {
		return other != null && Std.is(other, JBoolean) && _native == other._native;
	}
	public function compareTo(b:JBoolean):Int {
		return if(_native == b._native)
			0;
		else if(_native && !b._native)
			1;
		else if(!_native && b._native)
			-1;
	}
	public static function compare(a:Bool, b:Bool):Int {
		return if(a == b)
			0;
		else if(a && !b)
			1;
		else if(!a && b)
			-1;
	}
	public static function toString__(b:Bool):String {
		return b ? "true" : "false";
	}
	public static function getBoolean(name:String):JBoolean {
		return null; //JBoolean.valueOf(jax.lang.JSystem.getProperty(name, "") == "true");
	}
	public static function parseBoolean(v:String) {
		return JBoolean.valueOf(v.toLowerCase() == "true");
	}
	public static function valueOf(v:Dynamic) {
		return (Std.is(v, Bool) ? v : v.toLowerCase() == "true") ? JBoolean.TRUE : JBoolean.FALSE;
	}
}
